#!/bin/bash
#chkconfig:345 20 80
#description: lvs real server
VIP=192.168.0.192
case "$1" in
                start)
                        #start lvs
                        /sbin/ifconfig lo down
                        /sbin/ifconfig lo up
                        echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
                        echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
                        echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
                        echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
                        sysctl -p > /dev/null 2>&1
                        /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
                        /sbin/route add -host $VIP dev lo:0
                        ;;
                stop)
                        #stop lvs
                        /sbin/ifconfig lo:0 down
                        echo "0" > /proc/sys/net/ipv4/conf/lo/arp_ignore
                        echo "0" > /proc/sys/net/ipv4/conf/lo/arp_announce
                        echo "0" > /proc/sys/net/ipv4/conf/all/arp_ignore
                        echo "0" > /proc/sys/net/ipv4/conf/all/arp_announce
                        sysctl -p > /dev/null 2>&1
                        ;;
                status)
                        #status of lvs
                        islothere=`/sbin/ifconfig lo:0 |grep $VIP`
                        isrothere=`/netstat -rn |grep "lo" |grep "$VIP"`
                        if [ ! "islothere" -o ! "isrothere" ];then
                                        echo "the realserver is stopped"
                                else
                                        echo "realserver is running"
                        fi
                        ;;
                *)
                        echo "Usage:$0{start|stop|status}"
                exit 1
esac